package com.friend.campusnotice;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.widget.Toast;

import com.friend.campusnotice.adapter.CallLogAdapter;
import com.friend.campusnotice.bean.CallLog;
import com.friend.campusnotice.bean.Contacts;
import com.friend.campusnotice.util.MyUtil;

import java.util.ArrayList;
import java.util.List;

public class CallLogActivity extends AppCompatActivity {


    private RecyclerView recyleView;
    private List<CallLog> callLogList;
    private CallLogAdapter mCallLogAdapter;
    private Contacts contacts;
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            mCallLogAdapter.notifyDataSetChanged();
            Toast.makeText(CallLogActivity.this,"加载完了",Toast.LENGTH_LONG).show();

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_call_log);
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            contacts = bundle.getParcelable("contact");
            Log.i("xiaohei", contacts.toString());
        }
        callLogList = new ArrayList<CallLog>();
        MyUtil myUtil = new MyUtil();

        callLogList = myUtil.getSingleCall(CallLogActivity.this, contacts.getPhoneNumber());
        Log.i("xiaohei",callLogList.size()  + "  获取的通话记录长度");
       // initData();
        initView();


    }


    private void initData() {
        new Thread() {
            @Override
            public void run() {
                callLogList.clear();

                handler.sendEmptyMessage(0);

            }
        }.start();
    }


    private void initView() {

        recyleView = (RecyclerView) findViewById(R.id.swipe_target);
        mCallLogAdapter = new CallLogAdapter(CallLogActivity.this, callLogList);
        LinearLayoutManager layoutManager = new LinearLayoutManager(CallLogActivity.this);
        recyleView.setLayoutManager(layoutManager);
        recyleView.setAdapter(mCallLogAdapter);

    }
}
